import globals from 'globals';
import eslint from '@eslint/js';
import tsEsLint from 'typescript-eslint';
import eslintPluginVue from 'eslint-plugin-vue';
import vueParser from 'vue-eslint-parser';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

export default [
    {
        ignores: [
            '**/node_modules/**',
            '**/dist/**',
            '.gitignore',
            'package.json',
            'package-lock.json',
            '*.local',
            '.npmrc',
            '.DS_Store',
            '*.d.ts',
            '**/src/assets/**',
            '**/types/**',
            'scripts/**'
        ]
    },

    /** js 推荐配置 */
    eslint.configs.recommended,

    /** vue 推荐配置 */
    ...eslintPluginVue.configs['flat/recommended'],

    /** prettier 配置 */
    eslintPluginPrettierRecommended,

    /** ts 文件配置 */
    {
        files: ['**/*.{ts,tsx}'],
        languageOptions: {
            parser: tsEsLint.parser,
            globals: { ...globals.browser, ...globals.node },
            parserOptions: {
                ecmaVersion: 'latest',
                sourceType: 'module',
                project: './tsconfig.json'
            }
        },
        rules: {
            ...tsEsLint.configs.recommended.rules
        }
    },

    /** vue 文件配置 */
    {
        files: ['**/*.vue'],
        languageOptions: {
            parser: vueParser,
            globals: { ...globals.browser, ...globals.node },
            parserOptions: {
                parser: tsEsLint.parser,
                ecmaVersion: 'latest',
                ecmaFeatures: {
                    jsx: true
                }
            }
        },
        rules: {
            'vue/component-definition-name-casing': 'off',
            'vue/singleline-html-element-content-newline': 'off',
            'vue/no-mutating-props': ['error', { shallowOnly: true }],
            'vue/multi-word-component-names': 'off',
            'vue/comment-directive': 'off',
            'vue/valid-define-props': 'off',
            'vue/one-component-per-file': 'off',
            'vue/require-prop-types': 'off',
            'vue/attributes-order': 'off',
            'vue/require-default-prop': 'off',
            'vue/attribute-hyphenation': 'off',
            'vue/html-self-closing': 'off',
            'vue/html-closing-bracket-newline': 'off',
            'vue/no-v-html': 'off'
        }
    },

    /** 通用 js/ts/vue 规则 */
    {
        files: ['**/*.{js,mjs,cjs,vue,ts,tsx}'],
        rules: {
            'comma-dangle': 'off',
            'no-undef': 'off',
            quotes: ['error', 'single', { allowTemplateLiterals: true }],
            'no-undefined': 'off',
            'no-unused-vars': 'off',
            'no-irregular-whitespace': 'off',
            'space-before-function-paren': 0,
            'arrow-spacing': ['error', { before: true, after: true }],
            'block-spacing': ['error', 'always'],
            'brace-style': ['error', '1tbs', { allowSingleLine: true }],
            'object-property-newline': 'off',
            'jsx-quotes': ['error', 'prefer-single'],
            'key-spacing': ['error', { beforeColon: false, afterColon: true }],
            'keyword-spacing': ['error', { before: true, after: true }],
            'new-cap': ['error', { newIsCap: true, capIsNew: false }],
            'new-parens': 'error',
            'no-array-constructor': 'error',
            'no-caller': 'error',
            'no-class-assign': 'error',
            'no-cond-assign': 'error',
            'no-const-assign': 'error',
            'no-control-regex': 'off',
            'no-delete-var': 'error',
            'no-dupe-args': 'error',
            'no-dupe-class-members': 'error',
            'no-dupe-keys': 'error',
            'no-duplicate-case': 'error',
            'no-empty-character-class': 'error',
            'no-empty-pattern': 'error',
            'no-eval': 'error',
            'no-empty': 'error',
            'no-extra-boolean-cast': 'error',
            'no-extra-parens': ['error', 'functions'],
            'no-fallthrough': 'error',
            'no-floating-decimal': 'error',
            'no-func-assign': 'error',
            'no-unexpected-multiline': 'error',
            'no-useless-escape': 'off',
            'array-bracket-spacing': ['error', 'never'],
            '@typescript-eslint/no-unused-vars': 'off'
        }
    }
];
